package com.ruoyi.make.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.api.CodeClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.make.domain.KsMerchants;
import com.ruoyi.make.mapper.ScddProductionOrderFormMapper;
import com.ruoyi.make.domain.ScddProductionOrderForm;
import com.ruoyi.make.service.IScddProductionOrderFormService;

import javax.annotation.Resource;

/**
 * 生产订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@Service
public class ScddProductionOrderFormServiceImpl implements IScddProductionOrderFormService 
{
    @Resource
    private ScddProductionOrderFormMapper scddProductionOrderFormMapper;

    /**
     * 查询生产订单
     * 
     * @param ddCode 生产订单主键
     * @return 生产订单
     */
    @Override
    public ScddProductionOrderForm ddByCode(String ddCode)
    {
        System.out.println("service:"+ddCode);
        return scddProductionOrderFormMapper.ddByCode(ddCode);
    }

    /**
     * 查询生产订单列表
     * 
     * @param scddProductionOrderForm 生产订单
     * @return 生产订单
     */
    @Override
    public List<ScddProductionOrderForm> findAll(ScddProductionOrderForm scddProductionOrderForm)
    {
        return scddProductionOrderFormMapper.findAll(scddProductionOrderForm);
    }

    /**
     * 新增生产订单
     * 
     * @param scddProductionOrderForm 生产订单
     * @return 结果
     */
    @Resource
    private CodeClient codeClient;
    @Transactional
    @Override
    public int insertScddProductionOrderForm(ScddProductionOrderForm scddProductionOrderForm)
    {
        scddProductionOrderForm.setCreateTime(DateUtils.getNowDate());
        scddProductionOrderForm.setDdCode(codeClient.getCode(12));
        System.out.println(JSON.toJSONString("-------------------------------"+scddProductionOrderForm));
        int rows = scddProductionOrderFormMapper.insertScddProductionOrderForm(scddProductionOrderForm);
        return rows;
    }

    /**
     * 修改生产订单
     * 
     * @param scddProductionOrderForm 生产订单
     * @return 结果
     */
    @Transactional
    @Override
    public int updateScddProductionOrderForm(ScddProductionOrderForm scddProductionOrderForm)
    {
        scddProductionOrderForm.setUpdateTime(DateUtils.getNowDate());
        scddProductionOrderFormMapper.deleteKsMerchantsByKsCode(scddProductionOrderForm.getDdCode());
        return scddProductionOrderFormMapper.updateScddProductionOrderForm(scddProductionOrderForm);
    }


    /**
     * 批量删除生产订单
     * 
     * @param ddCodes 需要删除的生产订单主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteScddProductionOrderFormByDdCodes(String[] ddCodes)
    {
        scddProductionOrderFormMapper.deleteKsMerchantsByKsCodes(ddCodes);
        return scddProductionOrderFormMapper.deleteScddProductionOrderFormByDdCodes(ddCodes);
    }

    /**
     * 删除生产订单信息
     * 
     * @param ddCode 生产订单主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteScddProductionOrderFormByDdCode(String ddCode)
    {
        scddProductionOrderFormMapper.deleteKsMerchantsByKsCode(ddCode);
        return scddProductionOrderFormMapper.deleteScddProductionOrderFormByDdCode(ddCode);
    }


}
